package nowember.test_11_14;

import java.util.Scanner;

public class TestMain2 {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int t = sc.nextInt();
        for (int i = 0; i < t; i++) {
            int n = sc.nextInt();
            int[] arr = new int[n];
            for (int j = 0; j < n; j++) {
                arr[j] = sc.nextInt();
            }
            int operations = 0;
            for (int k = 1; k < n; k++) {
                if(arr[k - 1] > arr[k]) {
                    operations += arr[k - 1] - arr[k];
                }
                arr[k] = arr[k - 1];
            }
            System.out.println(operations);
        }

    }
}
